home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 26 / AMIGAplus Sonderheft 26 (2000)(Falke)(DE)(Track 1 of 2)[!].iso / Tools / GFX-Viewer / Animviewer / mpegvideo_datatype / mpegfloatdct.c < prev    next >
C/C++ Source or Header  |  1999-03-29  |  3KB  |  122 lines

  1.  
  2. /*
  3. **
  4. **  $VER: mpegfloatdct.c 1.11 (1.11.97)
  5. **  mpegvideo.datatype 1.11
  6. **
  7. **  Floating point DCT
  8. **
  9. **  Written 1996/1997 by Roland 'Gizzy' Mainz
  10. **  Original example source from David N. Junod
  11. **
  12. */
  13.  
  14.  
  15. /* idctref.c, Inverse Discrete Fourier Transform, double precision          */
  16.  
  17. /* Copyright (C) 1994, MPEG Software Simulation Group. All Rights Reserved. */
  18.  
  19. /*
  20.  * Disclaimer of Warranty
  21.  *
  22.  * These software programs are available to the user without any license fee or
  23.  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
  24.  * any and all warranties, whether express, implied, or statuary, including any
  25.  * implied warranties or merchantability or of fitness for a particular
  26.  * purpose.  In no event shall the copyright-holder be liable for any
  27.  * incidental, punitive, or consequential damages of any kind whatsoever
  28.  * arising from the use of these programs.
  29.  *
  30.  * This disclaimer of warranty extends to the user of these programs and user's
  31.  * customers, employees, agents, transferees, successors, and assigns.
  32.  *
  33.  * The MPEG Software Simulation Group does not represent or warrant that the
  34.  * programs furnished hereunder are free of infringement of any third-party
  35.  * patents.
  36.  *
  37.  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
  38.  * are subject to royalty fees to patent holders.  Many of these patents are
  39.  * general enough such that they are unavoidable regardless of implementation
  40.  * design.
  41.  *
  42.  */
  43.  
  44. /*  Perform IEEE 1180 reference (64-bit floating point, separable 8x1
  45.  *  direct matrix multiply) Inverse Discrete Cosine Transform
  46.  */
  47.  
  48.  
  49. /* Here we use math.h to generate constants.  Compiler results may
  50.    vary a little */
  51.  
  52. #include <math.h>
  53.  
  54. #ifndef PI
  55. # ifdef M_PI
  56. #  define PI M_PI
  57. # else
  58. #  define PI 3.14159265358979323846
  59. # endif
  60. #endif
  61.  
  62. /* global declarations */
  63. void init_float_idct( void );
  64. void float_idct( short *block );
  65.  
  66. /* private data */
  67.  
  68. /* cosine transform matrix for 8x1 IDCT */
  69. static double c[ 8 ][ 8 ];
  70.  
  71. /* initialize DCT coefficient matrix */
  72.  
  73. void init_float_idct( void )
  74. {
  75.   double scale;
  76.   int freq, time;
  77.  
  78.   for (freq=0; freq < 8; freq++)
  79.   {
  80.     scale = (freq == 0) ? sqrt(0.125) : 0.5;
  81.     for (time=0; time<8; time++)
  82.       c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5));
  83.   }
  84. }
  85.  
  86. /* perform IDCT matrix multiply for 8x8 coefficient block */
  87.  
  88. void float_idct( short *block )
  89. {
  90.   int i, j, k, v;
  91.   double partial_product;
  92.   double tmp[64];
  93.  
  94.   for (i=0; i<8; i++)
  95.     for (j=0; j<8; j++)
  96.     {
  97.       partial_product = 0.0;
  98.  
  99.       for (k=0; k<8; k++)
  100.         partial_product+= c[k][j]*block[8*i+k];
  101.  
  102.       tmp[8*i+j] = partial_product;
  103.     }
  104.  
  105.   /* Transpose operation is integrated into address mapping by switching
  106.      loop order of i and j */
  107.  
  108.   for (j=0; j<8; j++)
  109.     for (i=0; i<8; i++)
  110.     {
  111.       partial_product = 0.0;
  112.  
  113.       for (k=0; k<8; k++)
  114.         partial_product+= c[k][i]*tmp[8*k+j];
  115.  
  116.       v = floor(partial_product+0.5);
  117.       block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);
  118.     }
  119. }
  120.  
  121.  
  122.